package jgl.vajra.operator.part.login.activity;

import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import jgl.vajra.operator.R;
import jgl.vajra.operator.databinding.ActivityRegisterBinding;
import jgl.vajra.operator.manager.IntentManager;
import jgl.vajra.operator.part.login.contract.RegisterContract;
import jgl.vajra.operator.part.login.viewModel.RegisterViewModel;
import jgl.vajra.operator.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.operator.widget.mvvm.view.BaseMVVMActivity;
import jgl.vajra.operator.widget.utils.ToastUtils;
import jgl.vajra.operator.widget.utils.UIUtils;

@CreateViewModel(RegisterViewModel.class)
public class RegisterActivity extends BaseMVVMActivity<RegisterViewModel, ActivityRegisterBinding> implements RegisterContract.View {
    @Override
    public int getLayoutId() {
        return R.layout.activity_register;
    }

    @Override
    public void initView() {
        super.initView();
        mBinding.setView(this);

        setTextInfo(mBinding.tvRead,7,19);
    }

    //加盟要求
    @Override
    public void onJoiningRequirements() {
        IntentManager.toJoiningRequirementsActivity(this);
    }

    //老板司机
    @Override
    public void onBossDriver() {
        IntentManager.toHomeActivity(this);
        ToastUtils.showShort("老板司机");
    }

    //司机
    @Override
    public void onDriver() {
        ToastUtils.showShort("司机");
    }

    //是否同意
    @Override
    public void onAgreeStatus() {
        ToastUtils.showShort("是否同意");
    }


    /*  设置TextView中间字体颜色与点击事见
     *  start   开始文字的位置 坐标从 0开始
     *  end     改变结束的位置 ，并不包括这个位置。
     *  使用BackgroundColorSpan设置背景颜色。
     */
    private void setTextInfo(TextView tv ,int start,int end) {
        String content = tv.getText().toString();
        final SpannableStringBuilder style = new SpannableStringBuilder();
        style.append(content );//添加需要改变的文本
        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override
            public void updateDrawState(@NonNull TextPaint ds) {
                super.updateDrawState(ds);
                ds.setUnderlineText(false);//取消点击事见字体的背景颜色
                tv.setHighlightColor(getResources().getColor(android.R.color.transparent));
            }
            //变色字体点击监听设置
            @Override
            public void onClick(@NonNull View widget) {

                ToastUtils.showShort("变色字体的点击事件");
            }
        };
        style.setSpan(clickableSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv.setText(style);
        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(UIUtils.getColor(R.color.color_0f2cbb));
        style.setSpan(foregroundColorSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv.setMovementMethod(LinkMovementMethod.getInstance());
        tv.setText(style);
    }
}
